<?php

//Coded by Jonathan Gorard, 2012
//Part of The Matrix Unplugged, All Rights Reserved

	$macropage="training.php";
	include "globals.php";
	
	if($ir['hospital']) {
		die("This page cannot be accessed while in Reconstruction.");
	}

	$statnames=array('Combat' => 'strength','Coding' => 'agility','Hacking' => 'guard','Tactics' => 'labour');
	$_POST['amnt']=abs((int) $_POST['amnt']);
	
	if(!$ir['jail']){
		print "<h3>Training</h3><hr />";
	} else{
		print "<h3>Training</h3><hr />";
	}

	
	if($_POST['stat'] && $_POST['amnt']){
		$stat=$statnames[$_POST['stat']];
		
		if(!$stat)  {
			die("This stat cannot be trained.");
		}

		
		if($_POST['amnt'] > $ir['energy'])  {
			print("You do not have enough Focus to train that much.<hr />");
		} else  {
			$gain=0;
			for($i=0; $i<$_POST['amnt']; $i++)    {
				$gain+=rand(1,3)/rand(800,1000)*rand(800,1000)*(($ir['will']+20)/150);
				$ir['will']-=rand(1,3);
				
				if($ir['will'] < 0) {
					$ir['will']=0;
				}

			}

			
			if($ir['jail']) {
				$gain/=2;
			}

			$db->query("UPDATE `userstats` SET `{$stat}

		` = `{$stat}

	` + $gain WHERE `userid` = $userid");
	$db->query("UPDATE `users` SET `will` = {$ir['will']}

, energy = energy - {$_POST['amnt']}

 WHERE `userid` = $userid");
$inc=$ir[$stat]+$gain;
$inc2=$ir['energy']-$_POST['amnt'];

if($stat=="strength")    {
	print "You boot up a combat simulation program and begin taking out some virtual agents...<br />
      You have gained {$gain}

 combat skill by defeating {$_POST['amnt']}

 virtual agents.<br />
      You now have {$inc}

 combat skill and {$inc2}

 Focus left.";
}

elseif($stat=="agility")    {
	print "You boot up a coding simulation program and begin programming a simulacrum.<br />
      You have gained {$gain}

 coding skill by writing {$_POST['amnt']}

 lines of code.<br />
      You now have {$inc}

 coding skill and {$inc2}

 Focus left.";
}

elseif($stat=="guard")    {
	print "You boot up a hacking simulation program and begin brute-forcing some encryptions.<br />
      You have gained {$gain}

 hacking skill by breaking {$_POST['amnt']}

 encryption signatures.<br />
      You now have {$inc}

 hacking skill and {$inc2}

 Focus left.";
}

elseif($stat=="labour")    {
	print "You boot up a strategic simulation program and begin planning an assault.<br />
      You have gained {$gain}

 tactical skill by doing {$_POST['amnt']}

 minutes of planning.<br />
      You now have {$inc}

 tactical skill and {$inc2}

 Focus left.";
}

print "<hr />";
$ir['energy']-=$_POST['amnt'];
$ir[$stat]+=$gain;
}

}

$ir['strank']=get_rank($ir['strength'],'strength');
$ir['agirank']=get_rank($ir['agility'],'agility');
$ir['guarank']=get_rank($ir['guard'],'guard');
$ir['labrank']=get_rank($ir['labour'],'labour');
print "You plug yourself in and start running a simple training simulation.<br />
You can train up to {$ir['energy']}

 times.<hr />
<form action='training.php' method='post'>
Stat: <select type='dropdown' name='stat'>
<option style='color:red;' value='Combat'>Combat (Have {$ir['strength']}

, Ranked {$ir['strank']}

)
<option style='color:blue;' value='Coding'>Coding (Have {$ir['agility']}

, Ranked {$ir['agirank']}

)
<option style='color:green;' value='Hacking'>Hacking (Have {$ir['guard']}

, Ranked {$ir['guarank']}

)
<option style='color:brown;' value='Tactics'>Tactics (Have {$ir['labour']}

, Ranked {$ir['labrank']}

)
</select><br />
Times to train: <input type='text' name='amnt' value='{$ir['energy']}

' /><br />
<input type='submit' value='Train' /></form>";
$h->endpage();
?>
